
#include "Board.h"

int const Board::default_size = 8;

//When creating the board, add boundary to each side of the board, with the value 0.
Board::Board(void)
: matrix(new Matrix<int>(default_size + 2, default_size + 2))
{
}

Board::Board(int const& row, int const& column) throw()
: matrix(new Matrix<int>(row + 2, column + 2))
{
}

Board::~Board(void) throw()
{
}

Board::InfoType Board::getNeighborsInfo( size_t const& _row, size_t const& _column ) throw()
{
	try
	{
		Matrix<int> buffer(3, 3);

		buffer.at(0, 0) = matrix->at(_row,		_column);
		buffer.at(0, 1) = matrix->at(_row,		_column+1);
		buffer.at(0, 2) = matrix->at(_row,		_column+2);
		buffer.at(1, 0) = matrix->at(_row+1,	_column);
		buffer.at(1, 1) = matrix->at(_row+1,	_column+1);           //This is the middle square.
		buffer.at(1, 2) = matrix->at(_row+1,	_column+2);
		buffer.at(2, 0) = matrix->at(_row+2,	_column);
		buffer.at(2, 1) = matrix->at(_row+2,	_column+1);
		buffer.at(2, 2) = matrix->at(_row+2,	_column+2);

		return buffer;
	}
	catch(std::invalid_argument)
	{
		std::cout << "program bugs in Board::getNeighborsInfo" << std::endl;
		return Matrix<int>(3, 3);
	}
}

void Board::randomize(void)
{
	srand(static_cast<unsigned int>(time(NULL)));

	for (size_t r = 0; r != getRow(); ++r)
	{
		for (size_t c = 0; c != getColumn(); ++c)
		{
			this->setSquare(r, c, rand()%2);
		}
	}
}

std::vector<int> const * Board::toVector() const
{
	return matrix->toVector();
}